answer "A non-scrollable field cannot be scrolled." with ¬
"Sorry"
exit mouseUp
end if
end if
if fieldName is empty then getFieldInfo
if fieldName is not empty then numberLines
end mouseUp
on getFieldInfo
global fieldName,canScroll,canDo,goodID,theField
ask "Please enter field id number:" with theField
if it is not empty then
put it into theField
put it into theNumber
checkNumber
if goodID then
answer "Please select type of field:" with "Card" or "Background" ¬
or "Cancel"
if it is not "Cancel" then
if it is "Card" then
put the name of card field id theField into fieldName
else put the name of background field id theField into fieldName
if the style of fieldName is "scrolling" then
put true into canScroll
else put false into canScroll
put true into canDo
else put false into canDo
else
beep
answer "The field ID must be a number" with "Sorry"
getFieldInfo
end if
else
put false into canDo
if theField is empty
then answer "Insufficient information to proceed." with "OK"
end if
end getFieldInfo
on checkNumber
global theNumber,goodID
repeat with theChar = 1 to the number of characters in theNumber
get the charToNum of character theChar of theNumber
if it<48 or it>57 then
put false into goodID
exit checkNumber
end if
end repeat
put true into goodID
end checkNumber
on numberLines
global fieldName,canScroll
set the cursor to 4
set the lockScreen to true
set the textFont of card field "Line Numberer" to the textFont of ¬
fieldName
set the textSize of card field "Line Numberer" to the textSize of ¬
fieldName
put the rect of fieldName into fieldRect
if canScroll then
put (item four of fieldRect - item two of fieldRect) into it
divide it by the textHeight of fieldName
put trunc(it) into fieldLines
put fieldLines * the textHeight of fieldName into it
add item two of fieldRect to it
put it into item four of fieldRect
set the rect of fieldName to fieldRect
put the scroll of fieldName into numberOfLines
divide numberOfLines by the textHeight of fieldName
put trunc(numberOfLines) into numberOfLines
set the scroll of fieldName to (numberOfLines * the textHeight of ¬
fieldName)
else
put (item four of fieldRect - item two of fieldRect) into it
put trunc(it/the textHeight of fieldName) into numberOfLines
end if
put item one of fieldRect into item three of fieldRect
subtract 35 from item one of fieldRect --> Changes field width!
set the rect of card field "Line Numberer" to fieldRect
put 1 into lineCount
if canScroll then
repeat with theLine = (numberOfLines + 1) ¬
to (numberOfLines + fieldLines + 1)
put theLine into line lineCount of card field "Line Numberer"
add 1 to lineCount
end repeat
else
repeat with theLine = 1 to (numberOfLines + 1)
put theLine into line theLine of card field "Line Numberer"
end repeat
end if
set the lockScreen to false
end numberLines
</script>
</part>
<part>
<id>2</id>
<type>field</type>
<visible> <true /> </visible>
<dontWrap> <false /> </dontWrap>
<dontSearch> <false /> </dontSearch>
<sharedText> <false /> </sharedText>
<fixedLineHeight> <true /> </fixedLineHeight>
<autoTab> <false /> </autoTab>
<lockText> <false /> </lockText>
<rect>
<left>383</left>
<top>31</top>
<right>439</right>
<bottom>151</bottom>
</rect>
<style>scrolling</style>
<autoSelect> <false /> </autoSelect>
<showLines> <false /> </showLines>
<wideMargins> <false /> </wideMargins>
<multipleLines> <false /> </multipleLines>
<reservedFamily> 0 </reservedFamily>
<titleWidth>0</titleWidth>
<icon>0</icon>
<textAlign>left</textAlign>
<font></font>
<textSize>18</textSize>
<textStyle>plain</textStyle>
<textHeight>24</textHeight>
<name></name>
<script></script>
</part>
<part>
<id>3</id>
<type>field</type>
<visible> <true /> </visible>
<dontWrap> <false /> </dontWrap>
<dontSearch> <false /> </dontSearch>
<sharedText> <false /> </sharedText>
<fixedLineHeight> <true /> </fixedLineHeight>
<autoTab> <false /> </autoTab>
<lockText> <false /> </lockText>
<rect>
<left>252</left>
<top>37</top>
<right>307</right>
<bottom>149</bottom>
</rect>
<style>rectangle</style>
<autoSelect> <false /> </autoSelect>
<showLines> <false /> </showLines>
<wideMargins> <false /> </wideMargins>
<multipleLines> <false /> </multipleLines>
<reservedFamily> 0 </reservedFamily>
<titleWidth>0</titleWidth>
<icon>0</icon>
<textAlign>left</textAlign>
<font>Monaco</font>
<textSize>9</textSize>
<textStyle>plain</textStyle>
<textHeight>12</textHeight>
<name></name>
<script></script>
</part>
<part>
<id>6</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>4</left>
<top>316</top>
<right>88</right>
<bottom>337</bottom>
</rect>
<style>roundrect</style>
<showName> <true /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <true /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>0</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>reset card</name>
<script>on mouseUp
global fieldName,theField
set the lockScreen to true
set the cursor to 4
put empty into fieldName
put empty into theField
put empty into card field id 1
set the rect of card field id 1 to 55,97,90,217
set the textFont of card field id 1 to Monaco
set the textSize of card field id 1 to 9
set the rect of card field id 2 to 383,31,439,151
set the textFont of card field id 2 to London
set the textSize of card field id 2 to 18
set the scroll of card field id 2 to 0
set the rect of card field id 3 to 252,37,307,149
set the textFont of card field id 3 to Monaco
set the textSize of card field id 3 to 9
set the rect of background field id 1 to 383,206,494,302
set the textFont of background field id 1 to San Francisco
set the textSize of background field id 1 to 18
set the scroll of background field id 1 to 0
set the rect of card field id 15 to 129,226,347,337
set the lockScreen to false
end mouseUp
</script>
</part>
<part>
<id>7</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>100</left>
<top>159</top>
<right>142</right>
<bottom>182</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>1016</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>8</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>100</left>
<top>186</top>
<right>142</right>
<bottom>209</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>1016</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>9</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>100</left>
<top>132</top>
<right>142</right>
<bottom>155</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>1016</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>10</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>100</left>
<top>105</top>
<right>142</right>
<bottom>128</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>1016</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>11</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>4</left>
<top>105</top>
<right>47</right>
<bottom>128</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>32650</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>12</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>4</left>
<top>132</top>
<right>47</right>
<bottom>155</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>32650</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>13</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>4</left>
<top>159</top>
<right>47</right>
<bottom>182</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>32650</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>14</id>
<type>button</type>
<visible> <true /> </visible>
<reserved5> 0 </reserved5>
<reserved4> 0 </reserved4>
<reserved3> 0 </reserved3>
<reserved2> 0 </reserved2>
<reserved1> 0 </reserved1>
<enabled> <true /> </enabled>
<rect>
<left>4</left>
<top>186</top>
<right>47</right>
<bottom>209</bottom>
</rect>
<style>transparent</style>
<showName> <false /> </showName>
<highlight> <false /> </highlight>
<autoHighlight> <false /> </autoHighlight>
<sharedHighlight> <true /> </sharedHighlight>
<family>0</family>
<titleWidth>0</titleWidth>
<icon>32650</icon>
<textAlign>center</textAlign>
<font>Chicago</font>
<textSize>12</textSize>
<textStyle>plain</textStyle>
<name>New Button</name>
<script></script>
</part>
<part>
<id>15</id>
<type>field</type>
<visible> <true /> </visible>
<dontWrap> <false /> </dontWrap>
<dontSearch> <false /> </dontSearch>
<sharedText> <false /> </sharedText>
<fixedLineHeight> <true /> </fixedLineHeight>
<autoTab> <false /> </autoTab>
<lockText> <false /> </lockText>
<rect>
<left>129</left>
<top>226</top>
<right>347</right>
<bottom>337</bottom>
</rect>
<style>scrolling</style>
<autoSelect> <false /> </autoSelect>
<showLines> <false /> </showLines>
<wideMargins> <false /> </wideMargins>
<multipleLines> <false /> </multipleLines>
<reservedFamily> 0 </reservedFamily>
<titleWidth>0</titleWidth>
<icon>0</icon>
<textAlign>left</textAlign>
<font>Monaco</font>
<textSize>9</textSize>
<textStyle>plain</textStyle>
<textHeight>12</textHeight>
<name></name>
<script></script>
</part>
<content>
<layer>card</layer>
<id>2</id>
<text>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</text>
</content>
<content>
<layer>background</layer>
<id>1</id>
<text>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20</text>
</content>
<content>
<layer>card</layer>
<id>3</id>
<text>1
2
3
4
5
6
7
8
9
10
</text>
</content>
<content>
<layer>card</layer>
<id>15</id>
<text>
NOTICE: This stack and the items in it are not protected by copyright. Use it, peruse it, or abuse it as you will. No charge.
OTHER NOTICE: Sure I know this card looks cluttered and is poorly designed. If I was an artist I wouldn't be wasting my time creating such silly stackware or writing these silly instructions to go with it. Give me a break.
RAISON D'ETRE, or, how come I made this field:
HyperCard‚Ñ¢ offers little in the way of data structures. If you want to make an array you have to use a field, and for very large arrays a scrollable field is often used. So let's say you have a scrollable field with several hundred lines of information, and you decide you want to check line 75 for errors. How do you find line 75? It is an arduous task (a.k.a. a pain in the... neck).
Now there is an easy solution! You just copy the field named "Line Numberer" (pointed out above to the left) into the same stack as the field you need to check, and with a click of a mouse button (or three, if you haven't yet told Line Numberer which field you want to check) the lines of the field are numbered for you. Wow! If you want to scroll to a specific line and have it numbered too, Line Numberer can do that, too! Wowee!
HOW TO USE LINE NUMBERER:
1. To reduce surprises, be sure to press the "reset card" button (located to the left) before taking the field from this card.
2. Copy the field labeled "Line Numberer" (also located to the left).
3. Paste the copy of the Line Numberer field into THE CARD LAYER of the stack in which you want to use it. It will not work in the background layer unless you change information in the field's script.
4. To use the field perform a mouseUp anyplace over the field.
5. You will be asked for THE ID NUMBER of the field you want numbered. Enter the appropriate ID number and press "OK".
6. You will be asked whether the field in question is a Card or Background field. Press the appropriate button.
7. The Line Numberer field will align itself with the left side of the field you have selected, change its font to match the field, and number the lines.
8. If you change the scroll position of your field and wish to have it renumbered simply mouseUp over the Line Numberer field. The field will be renumbered without supplying any additional information.
9. To switch to another field hold the option button down during the mouseUp. You will be prompted to supply the ID number, etc., of the new field.
10. To scroll to a specific line hold down the shift key during the mouseUp. You will be prompted to supply the line number to which you would like to scroll. Your field will then be scrolled to that point and the line will be numbered.
11. Once you have told Line Numberer which field you want it to number it will be attached to that field until you switch it to another field (option mouseUp) or until you quit HyperCard‚Ñ¢. This means that if you move the field around, change its rectangle, or font, or whatever, as soon as you do a mouseUp over the Line Numberer field it will move to the left side of your field and renumber itself.
12. Line Numberer will also number the lines of non-scrollable fields. You may not specify a line number to scroll to with a non-scrollable field, however.
WARNING!
Before you use Line Numberer in one of your stacks please note that Line Numberer may change the rectangle or the scroll setting of a scrollable field to which it is attached.
Why?
In order for Line Numberer to accurately number the lines of a scrollable field, two conditions must be met.
First, the distance from the top to the bottom of the field must be an exact number of lines. If your field is, for example, three and a half lines long, when you scroll the field with the arrow buttons or by paging (pressing the mouse in the gray slide bar) you can end up with only part of a line showing at the top or bottom of the field. Since the Line Numberer field is not scrollable, it cannot shift its contents to match those of your field. So it will shorten your field to the next whole line number.
Second, if you move around in your field by dragging the thumb (white box in slide bar) or by setting it from a script or the message box you can also end up with a partial line showing at the top or bottom of your field. In this case Line Numberer will scroll your field down to display the nearest whole line.
Of course, the first point can also be useful. In order for your fields to scroll neatly they must be an exact number of lines in height. This can be impossible to do by hand (a hit or miss problem), or involves calculating font information. An easy solution is to stretch the field to the approximate length you want, then attach Line Numberer to it. Your field will then be perfectly sized for its font. If you change the font while Line Numberer is attached to the field, just mouseUp on the Line Numberer field and it will resize your field again if necessary.
TRY IT OUT HERE FIRST!
The three labeled fields on this card (above and to the right) are example fields. The ID information is listed under each field so you don't have to search the field information to get it. Click on the Line Numberer field and supply the ID information from one of the other fields on the card and see how it works. Scroll the field (if it is scrollable) and click on the Line Numberer field again. Resize the field and move it around. Change its font. Shift Line Numberer to one of the other fields. Scroll to a specific point in the field. The fields are all numbered to twenty so you can see how the line numbers match up.
When you are finished press the "reset card" button in the lower left corner and the card's contents will be restored to their original state.
KNOWN LIMITATIONS:
1. If your field is so far to the left that the Line Numberer field is offscreen, it won't work too well. In fact, if you attach it to a hidden field I suppose it will leap right off the screen.
2. Only one copy of Line Numberer can be used at a time without modifying its script. Because of this, if you should lose Line Numberer off the edge of your card (see limitation number 1, above) you cannot simply bring in another copy and have it work. If all else fails, typing: set the rect of card field "Line Numberer" to 100,100,200,200 will bring it back onscreen. However, if it was attached to an offscreen field, clicking on the Line Numberer field will make it fly offscreen again, so be sure to do an option-click to change it to a visible field.
3. The Line Numberer field must be placed in the card layer of your stack or it will not work (unless, of course, you modify its script).
4. The width of the Line Numberer field is fixed. If the font of your field is so large it won't fit (too wide), or there are so many lines the number is too wide for the field, it will look bad. A simple modification of the Line Numberer field's script will adjust the width of the field. The line to change is in the numberLines message handler, and is the only commented line in the entire script. A larger number will widen the field, a smaller number will make it narrower.
AT LAST, THE CREDITS!
Anyone wishing to contact me may do so in the following ways.
Compuserve:
William G. Anderson, Jr.
76254,356
GEnie:
OTISGVARY (I'm not sure about this one, it's a guess)